package com.fengkai.filepost.pdfoutstream.test;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author Fengkai
 * @creat 2022/9/28
 */
public class Pinyin {
       public static void main(String[] args){
           Predicate<String> ssh = (String s) -> s.length() >= 8;
           Predicate<String> ssw = (String s) -> s.contains("zzc");
           boolean zzcaisudhwnal = ssw.and(ssh).test("zzcaisudhwnal");
           boolean asdawsfawg = ssw.and(ssh).test("asdawsfawg");
           System.out.println(zzcaisudhwnal);
           System.out.println(asdawsfawg);

           Function<String, Integer> f1 = (String s) ->{
               String substring = s.substring(0, s.length() - 1);
               return Integer.valueOf(substring.charAt(substring.length() / 2));
           };
           System.out.println(f1.apply("asdageawe"));

       }

          public static String toFirstChar(String chinese){
              String pinyin = "";
              char[] newChar = chinese.toCharArray();
              HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
              defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);
              defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
              for (int i = 0; i < newChar.length; i++) {
                  if (newChar[i] > 128) {
                      try {
                          pinyin += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0].charAt(0);
                      } catch (BadHanyuPinyinOutputFormatCombination e) {
                          e.printStackTrace();
                      }
                  }else {
                      pinyin += newChar[i];
                  }

              }
              return pinyin;
          }

          public static String getContractNum(String spcactName){
              SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyyMMdd");
              String importDay = yyyyMMdd.format(new Date());
              StringBuffer OUTPUT_ = new StringBuffer("ZSCF-");
                if (spcactName.contains("招商财富")){
                    String coding = spcactName.replaceAll("招商财富", "").replaceAll("\\p{Punct}", "");
                    if (coding.contains("单一") ) {
                        coding = coding.substring(0, coding.indexOf("单一"));
                    }else if ( coding.contains("集合")){
                        coding = coding.substring(0, coding.indexOf("集合"));
                    }else {
                        coding = coding.substring(0, 7);
                    }
                    OUTPUT_.append(coding).append("-QRS-HT-").append(importDay);
                }else {
                    OUTPUT_.append(spcactName.substring(0, spcactName.length()/2)).append("-QRS-HT-").append(importDay);
                }
                return Pinyin.toFirstChar(OUTPUT_.toString());
          }
}
